import QtQuick 1.0

Item {
        id:screen
        property int speedX: 10
        property int speedY: 10
        property int framesCount:4
        property int currentFrame:0
        property int intervalTime: 100
        property int intervalTimeMove: 100
        property string sourceImg

        Item{
            id:spriteAnimation

            anchors.centerIn: parent.Center
            clip:true

            height:spriteAnimationImage.height
            width:spriteAnimationImage.width/framesCount

            Image{
                id:spriteAnimationImage
                source: sourceImg
                y:0
                x:-spriteAnimation.width*currentFrame
            }
        }

        Timer{
            id:spriteAnimationTimer
            interval: intervalTime
            running:true
            repeat:true
            onTriggered:{
                currentFrame++
                currentFrame%=framesCount
            }
        }

        Timer{
            id:movingTimer
            interval: intervalTimeMove
            running:true
            repeat:true
            onTriggered:{
                parent.x += speedX
                parent.y += speedY
            }
        }

        function moveRight()
        {
            sourceImg = "images/main_screen/sprite-ga-di-phai.png"
            framesCount = 4
            currentFrame = 0
            intervalTime = 300
            intervalTimeMove = 200
            speedX = 5
            speedY = 0
        }
        function moveLeft()
        {
            sourceImg = "images/main_screen/sprite-ga-di-trai.png"
            framesCount = 4
            currentFrame = 0
            intervalTime = 300
            intervalTimeMove = 200
            speedX = -5
            speedY = 0
        }
        function moveFront()
        {
            sourceImg = "images/main_screen/sprite-ga-di-toi.png"
            framesCount = 4
            currentFrame = 0
            intervalTime = 300
            intervalTimeMove = 200
            speedX = 0
            speedY = 5
        }
        function moveBack()
        {
            sourceImg = "images/main_screen/sprite-ga-di-lui.png"
            framesCount = 4
            currentFrame = 0
            intervalTime = 300
            intervalTimeMove = 200
            speedX = 0
            speedY = -5
        }
        function eat()
        {
            sourceImg = "images/main_screen/sprite-ga-an-l.png"
            framesCount = 10
            currentFrame = 0
            intervalTime = 300
            intervalTimeMove = 200
            speedX = 0
            speedY = 0
        }
        function fight()
        {
            sourceImg = "images/main_screen/sprite-ga-di-toi.png"
            framesCount = 4
            currentFrame = 0
            intervalTime = 300
            intervalTimeMove = 200
            speedX = 0
            speedY = 0
        }
    }
